package com.base.jdk8.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class HelloSortedStream {
    public static void main(String[] args) {
//        iteratorList();
//        getNumSquare();
        getDoubleNumber();
    }

    private static void iteratorList() {
        List<String> cities = new ArrayList<>(3);
        cities.add("上海");
        cities.add("北京");
        cities.add("天津");
        cities.add("天津2");
        cities.add("天津3");

        List<String> resultList =
                cities.stream().filter(city -> city.contains("天津")).distinct().limit(1).collect(Collectors.toList());
        System.out.println("resultList = " + resultList);
    }

    public static void getNumSquare() {
        List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5);
        List<Integer> squareList = integers.stream().map(num -> num * num).collect(Collectors.toList());
        System.out.println("squareList = " + squareList);
    }

    public static void getDoubleNumber() {
        List<Integer> firstNumbers = Arrays.asList(1, 2, 3);
        List<Integer> secondNumbers = Arrays.asList(4, 5);

        List<int[]> resultList =
                firstNumbers.stream().flatMap(n -> secondNumbers.stream().map(m -> new int[]{n, m})).collect(Collectors.toList());

        for (int[] ints : resultList) {
            System.out.println(Arrays.toString(ints));
        }
    }
}
